package com.gitee.linmt.service.impl;

import com.gitee.linmt.entity.UserInfo;
import com.gitee.linmt.repository.UserInfoRepository;
import com.gitee.linmt.service.RoleService;
import com.gitee.linmt.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author linmt
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {

    private final UserInfoRepository userInfoRepository;

    private final RoleService roleService;

    public UserInfoServiceImpl(UserInfoRepository userInfoRepository, RoleService roleService) {
        this.userInfoRepository = userInfoRepository;
        this.roleService = roleService;
    }

    @Override
    public UserInfo findByUsername(String username) {
        UserInfo userInfo = userInfoRepository.getByUsername(username);
        userInfo.setRoleList(roleService.listByUserId(userInfo.getId()));
        return userInfo;
    }

    @Override
    public void save(UserInfo userInfo) {
        userInfoRepository.save(userInfo);
    }
}
